package com.atguigu.springcloud.cloudsentinelgatewaydevelop.controller;

import com.atguigu.springcloud.cloudsentinelgatewaydevelop.bean.dto.SentinelDegradeRuleDTO;
import com.atguigu.springcloud.cloudsentinelgatewaydevelop.service.DegradeRuleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 降级规则控制器
 *
 * @author Anonymous
 * @version 1.0
 * @since 2022/3/11 11:18
 */
@RestController
@RequestMapping("/degraderule")
@RequiredArgsConstructor
public class DegradeRuleController {

    private final DegradeRuleService degradeRuleService;

    @PostMapping("/save")
    public Mono<Integer> save(@RequestBody SentinelDegradeRuleDTO sentinelDegradeRuleDTO) {
        return degradeRuleService.save(sentinelDegradeRuleDTO);
    }

    @GetMapping("/find/{id}")
    public Mono<SentinelDegradeRuleDTO> getById(@PathVariable("id") Long id) {
        return degradeRuleService.findById(id);
    }

    @GetMapping("/finds/{applicationName}")
    Mono<List<SentinelDegradeRuleDTO>> findByApplicationName(@PathVariable("applicationName") String applicationName) {
        return degradeRuleService.findByApplicationName(applicationName).collectList();
    }

    @DeleteMapping("/delete/{id}")
    Mono<Integer> deleteById(@PathVariable Long id) {
        return degradeRuleService.deleteById(id);
    }

    @DeleteMapping("/deletes/{applicationName}")
    Mono<Integer> deleteByAyApplicationName(@PathVariable("applicationName") String applicationName) {
        return degradeRuleService.deleteByAyApplicationName(applicationName);
    }

}
